// // Copyright (c) 2009 All Right Reserved // // Stephen Toub // stoub@microsoft.com // 2009-01-01 // Contains ... using System; using System.Globalization; using System.IO; using System.Text; namespace LargoCommon.Midi { /// Represents a meta event message. [Serializable] public abstract class MetaEvent : MidiEvent { #region Fields /// The ID of the meta event. private readonly byte metaEventId; #endregion #region Constructors /// Initializes a new instance of the MetaEvent class. /// The amount of time before this event. /// The ID of the meta event. protected MetaEvent(long deltaTime, byte givenMetaEventId) : base(deltaTime) { this.metaEventId = givenMetaEventId; } #endregion #region Properties /// Gets the ID of this meta event. /// General musical property. private byte MetaEventId => this.metaEventId; #endregion #region To String /// Generate a string representation of the event. /// A string representation of the event. public override string ToString() { var sb = new StringBuilder(); sb.Append(base.ToString()); sb.Append("\t"); sb.Append(" MetaId=0x"); sb.Append(this.MetaEventId.ToString("X2", CultureInfo.CurrentCulture.NumberFormat)); return sb.ToString(); } #endregion #region Methods /// Write the event to the output stream. /// The stream to which the event should be written. public override void Write(Stream outputStream) { if (outputStream == null) { return; } //// Write out the base event information base.Write(outputStream); // Special meta event marker and the id of the event outputStream.WriteByte(0xFF); outputStream.WriteByte(this.metaEventId); } #endregion } }